package ${package.Controller};

import com.alibaba.dubbo.config.annotation.Reference;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.xieke.test.tyqxcms.dto.ResultInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
<#if  restControllerStyle >
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage?? >
import ${superControllerClassPackage};
</#if>

/**
 * <p>
    * $!{table.comment} 前端控制器
    * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle >
@RestController
<#else>
@Controller
</#if>
@RequestMapping("/${table.entityPath}")
<#if kotlin>
class ${table.controllerName} <#if superControllerClass > : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
public class ${table.controllerName} extends BaseController {
    </#if>

    @Reference(version = "1.0.0")
    private ${table.serviceName} i${table.entityPath}Service;

    @RequestMapping("/*")
    public void toHtml(){

    }

    @RequestMapping("/listData")
    @RequiresPermissions("${table.entityPath}:view")
    public @ResponseBody
        ResultInfo
<List<${entity}>> listData(${entity} ${table.entityPath}, Integer page, Integer limit){
        EntityWrapper<${entity}> wrapper = new EntityWrapper<>(${table.entityPath});
        Page<${entity}> pageObj = i${table.entityPath}Service.selectPage(new Page<>(page,limit), wrapper);
        return new ResultInfo<>(pageObj.getRecords(), pageObj.getTotal());
    }

    @RequestMapping("/add")
    @RequiresPermissions("${table.entityPath}:add")
    public @ResponseBody
        ResultInfo
<Boolean> add(${entity} ${table.entityPath}){
    boolean b = i${table.entityPath}Service.insert(${table.entityPath});
    return new ResultInfo<>(b);
    }

    @RequestMapping("/delBatch")
    @RequiresPermissions("${table.entityPath}:del")
    public @ResponseBody
    ResultInfo
    <Boolean> delBatch(Integer[] idArr){
        boolean b = i${table.entityPath}Service.deleteBatchIds(Arrays.asList(idArr));
        return new ResultInfo<>(b);
        }

        @RequestMapping("/edit")
        @RequiresPermissions("${table.entityPath}:edit")
        public @ResponseBody
        ResultInfo
        <Boolean> edit(${entity} ${table.entityPath}){
            boolean b = i${table.entityPath}Service.updateById(${table.entityPath});
            return new ResultInfo<>(b);
            }

            }
</#if>
